package com.sheng.controller;

import com.sheng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class UserController {

    @Autowired
    @Qualifier("userServiceImpl")
    public UserService userService;

    @PostMapping("/login")
    public String login(@RequestParam("username") String username,@RequestParam("password") String password , RedirectAttributes model){
        if(userService.login(username,password)){
            model.addFlashAttribute("tip","登录成功");
            return "redirect:success";
        }
        model.addFlashAttribute("tip","登录失败");
        return "redirect:error";
    }

    @GetMapping("/success")
    public String success(){
        return "success";
    }
    @GetMapping("/error")
    public String error(){
        return "error";
    }

}
